/**
 *var $username   用户名
 var $password   mima
 var $userid     id
 var user        all
 url="http://localhost:8080/person/"
 */

$(document).ready(function () {


    $.ajax({
        url:url+"person/follow.do",
        type:"get",
        datatype:"json",
        data:{username:$username},
        success:function(data){
            var arry = JSON.parse(data);
            for(var i=0,j=arry.length;i<j;i++)
            {
                addResult(arry[i])
            }
        }

    })
})

function addResult(data) {
        $('tbody').append("<tr>" +
            "<td>"+data.roomid+"</td>" +
            "<td>"+data.roomname+"</td>" +
            "<td>"+data.roommaster+"</td>" +
            "<td>"+getStatus(data.status)+"</td>" +
            "<td><i class='fa fa-times fa-lg text-danger' title='取消关注' onclick='deleteResult(this)'></i></td>" +
            "</tr>")

}

function getStatus(status) {
    if(status==0)
    {
        return '<span class="label label-danger">关闭</span>';

    }else if(status==1)
    {
        return "<span class='label label-success'>直播中</span>"
    }
}



function deleteResult(t)
{
    var tr = $(t).parents("tr").eq(0);
    var td =tr.find("td").eq(0);
    var json={username:$username,roomid:td.text()}
    $.ajax({
        url:url+'person/unfollow.do',
        type:"get",
        datatype:"json",
        data:json,
        success:function (data) {
            if(data == "success")
            {
                tr.remove();
                $('#AlertSuccess').removeClass("hide");
            }
        }
    })

    $('.close').on("click",function () {
        $(this).parents('div').eq(0).addClass('hide');
    })

}